import Taro from "@tarojs/taro"


const baseUrl = 'http://47.107.64.214'

export const request = (url, method, data, dataType = 'json') => {
    Taro.request({
        url: baseUrl + url,
        method,
        data,
        dataType,
        header: {
            'content-type': 'application/json'
        },
        success: function (res) {
            console.log(res, 'res')
            if (res.data) {
                const { code,msg } = res.data
                if (code == 200) {
                    return res.data
                }else if(code==500){
                    Taro.showToast({
                        title:msg,
                        icon:'error'
                    })
                    return null
                }
            }
        },
        fail: (err) => {
            console.log(err, 'err')
            Taro.showToast({
                title:err,
                icon:'error'
            })
        },
    })
}